/*
 *
 * esda/utils/TimeUtils.cxx --
 *
 * Copyright (C) Olivier Le Floch
 *
 * See the file LICENSE for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 */

#include <esda/config.H>

#include <esda/utils/TimeUtils.H>
#include <esda/core/Timestamp.H>

#include <sys/time.h>

namespace esda {

	// -----------------------------------------------------------------------------

	void
	Chronometer::start(void) {
		_count = 0 ;
		_running = true ;
		_laps = 0 ;
		_epoch = Timestamp::createAsInt() ;
	}

	Timestamp::inttype
	Chronometer::read(void) {
		if (!_running) return _laps ;
		return Timestamp::createAsInt()-_epoch ;
	}

	void
	Chronometer::stop(void) {
		_laps = Timestamp::createAsInt()-_epoch ;	
		_running = false ;
	}

	void
	Chronometer::reset(void) {
		stop() ;
		_laps = 0 ;
		_count = 0 ;
	}

	// -----------------------------------------------------------------------------

}
